<?php
//error_reporting(E_ERROR|E_PARSE);
header("Content-Type:text/html; charset=utf-8");
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
$conn = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname,$conn);
function export_xls($filename,$table){
    $exportString=$table;
 
    header("Cache-Control:public");
    header("Pragma:public");
    header("Content-type: Content-type:application/vnd.ms-excel");
    header("Accept-Ranges: bytes");
    header("Content-Disposition:attachment; filename=".$filename);
    header("Content-length:".strlen($exportString));
    echo $exportString;
    exit;
}
function replacebd($str1,$str2){
 $s1=explode("Brand Name:",$str1);
 $s2=explode('&lt;br/&gt;',$s1[1]);
 $s3=str_replace($s2[0],$str2,$str1);
 return $s3;
}
function randomkeys($length)   
{   
   //$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ'; 
      $str = null;
      $strPol = "123456789";//大小写字母以及数字
      $max = strlen($strPol)-1;
      
      for($i=0;$i<$length;$i++){
         $str.=$strPol[rand(0,$max)];
      }
      return $str;
}
function EAN13($n){
        $n=(string)$n;
        $a=(($n[1]+$n[3]+$n[5]+$n[7]+$n[9]+$n[11])*3+$n[0]+$n[2]+$n[4]+$n[6]+$n[8]+$n[10])%10;
        $a=$a==0?0:10-$a;
        return $n.$a;
    }
$lang=$_GET["lang"];
$bname=$_GET["bname"];
$brand=$_POST["brand"];
$ProductType=$_POST["ProductType"];
$manufacturer=$_POST["manufacturer"];
$recommended=$_POST["recommended"];
$user_name=$_SESSION["managername"];
if($_SESSION["thetype"]=="管理员"){$sql="select * from ph_".$lang." where 1=1";}else{$sql="select * from ph_".$lang." where 1=1 and user_name='".$_SESSION["managername"]."'";}
if($bname!==''&&isset($bname)){$sql.=" and bname ='".$bname."'";}
$result=mysql_query($sql);
$tablehead='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
</head>
<body>
<table cellpadding="0" cellspacing="0">
  <col width="157" span="5" />
  <col width="178" />
  <col width="157" span="167" />
  <tr height="45">
    <td height="45" width="157">TemplateType=fptcustom</td>
    <td width="157">Version=2018.0727</td>
    <td width="157">TemplateSignature=S0lUQ0hFTg==</td>
    <td colspan="2" width="314">The top 3 rows are for Amazon.com use only. Do not</td>
    <td width="178"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Images</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Variation</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Basic</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Discovery</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Product Enrichment</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Dimensions</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Fulfillment</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Compliance</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">Offer</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157">b2b</td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
    <td width="157"></td>
  </tr>
  <tr height="45">
    <td height="45">Product Type</td>
    <td>Seller SKU</td>
    <td>Brand Name</td>
    <td>Product Name</td>
    <td>Manufacturer</td>
    <td>Recommended Browse Nodes</td>
    <td>Standard Price</td>
    <td>Quantity</td>
    <td>Merchant Shipping Group</td>
    <td>Main Image URL</td>
    <td>Swatch Image URL</td>
    <td>Other Image Url</td>
    <td>Other Image Url</td>
    <td>Other Image Url</td>
    <td>Other Image Url</td>
    <td>Other Image Url</td>
    <td>Other Image Url</td>
    <td>Other Image Url</td>
    <td>Other Image Url</td>
    <td>Parentage</td>
    <td>Parent SKU</td>
    <td>Relationship Type</td>
    <td>Variation Theme</td>
    <td>Update Delete</td>
    <td>GTIN Exemption Reason</td>
    <td>Product ID</td>
    <td>Product ID Type</td>
    <td>Manufacturer Part Number</td>
    <td>Product Description</td>
    <td>Merchant Catalogue Number</td>
    <td>Key Product Features</td>
    <td>Key Product Features</td>
    <td>Key Product Features</td>
    <td>Key Product Features</td>
    <td>Key Product Features</td>
    <td>Search Terms</td>
    <td>Search Terms</td>
    <td>Search Terms</td>
    <td>Search Terms</td>
    <td>Search Terms</td>
    <td>Platinum Keyword</td>
    <td>Platinum Keyword</td>
    <td>Platinum Keyword</td>
    <td>Platinum Keyword</td>
    <td>Platinum Keyword</td>
    <td>Home & Furniture Target Audience</td>
    <td>size_map</td>
    <td>length_range</td>
    <td>width_range</td>
    <td>Scent</td>
    <td>Colour</td>
    <td>Color Map</td>
    <td>Size</td>
    <td>Material Type</td>
    <td>Item Width Unit Of Measure</td>
    <td>item_width</td>
    <td>item_height</td>
    <td>Item Height Unit Of Measure</td>
    <td>Item Dimensions Unit Of Measure</td>
    <td>Item Length Unit Of Measure</td>
    <td>item_length</td>
    <td>Display Depth</td>
    <td>Item Display Depth Unit Of Measure</td>
    <td>Shipping Weight</td>
    <td>Website Shipping Weight Unit Of Measure</td>
    <td>Vacuum Sealer Bag Length</td>
    <td>Item Display Length Unit Of Measure</td>
    <td>Display Width</td>
    <td>Item Display Width Unit Of Measure</td>
    <td>Display Height</td>
    <td>Item Display Height Unit Of Measure</td>
    <td>Display Diameter</td>
    <td>Item Display Diameter Unit Of Measure</td>
    <td>Vacuum & Floor Care Item Weight</td>
    <td>Item Display Weight Unit Of Measure</td>
    <td>Volume</td>
    <td>Volume Capacity Name Unit Of Measure</td>
    <td>Volume Capacity of the appliance</td>
    <td>Item Display Volume Unit Of Measure</td>
    <td>Package Weight Unit Of Measure</td>
    <td>Package Dimensions Unit Of Measure</td>
    <td>package_weight</td>
    <td>Package Length</td>
    <td>Package Width</td>
    <td>Package Height</td>
    <td>Fulfillment Centre ID</td>
    <td>specific_uses_for_product1</td>
    <td>specific_uses_for_product2</td>
    <td>specific_uses_for_product3</td>
    <td>specific_uses_for_product4</td>
    <td>specific_uses_for_product5</td>
    <td>Product fiche</td>
    <td>Energy efficiency label</td>
    <td>legal_disclaimer_description</td>
    <td>safety_warning</td>
    <td>fedas_id</td>
    <td>EU Toys Safety Directive Age-Specific Warning</td>
    <td>EU Toys Safety Directive Non-Age-Specific Warning</td>
    <td>EU Toys Safety Directive Language Warning</td>
    <td>Country/Region of declaration</td>
    <td>Batteries are Included</td>
    <td>Is this product a battery or does it utilise batte</td>
    <td>Battery type/size</td>
    <td>Battery type/size</td>
    <td>Battery type/size</td>
    <td>Number of batteries</td>
    <td>Number of batteries</td>
    <td>Number of batteries</td>
    <td>Battery composition</td>
    <td>Battery weight (grams)</td>
    <td>battery_weight_unit_of_measure</td>
    <td>Number of Lithium Metal Cells</td>
    <td>Number of Lithium-ion Cells</td>
    <td>Lithium Battery Packaging</td>
    <td>Watt hours per battery</td>
    <td>lithium_battery_energy_content_unit_of_measure</td>
    <td>Lithium content (grams)</td>
    <td>lithium_battery_weight_unit_of_measure</td>
    <td>Applicable Dangerous Goods Regulations</td>
    <td>Applicable Dangerous Goods Regulations</td>
    <td>Applicable Dangerous Goods Regulations</td>
    <td>Applicable Dangerous Goods Regulations</td>
    <td>Applicable Dangerous Goods Regulations</td>
    <td>UN number</td>
    <td>Safety Data Sheet (SDS) URL</td>
    <td>Item Weight</td>
    <td>item_weight_unit_of_measure</td>
    <td>Volume</td>
    <td>item_volume_unit_of_measure</td>
    <td>Flash point (°C)?</td>
    <td>Categorization/GHS pictograms (select all that app</td>
    <td>Categorization/GHS pictograms (select all that app</td>
    <td>Categorization/GHS pictograms (select all that app</td>
    <td>Recommended Retail Price</td>
    <td>weee_tax_value</td>
    <td>Number of Items</td>
    <td>weee_tax_value_unit_of_measure</td>
    <td>Stop Selling Date</td>
    <td>Max Order Quantity</td>
    <td>Offering Release Date</td>
    <td>Scheduled Delivery SKU List</td>
    <td>Launch Date</td>
    <td>Currency</td>
    <td>Package Quantity</td>
    <td>Product Tax Code</td>
    <td>Release Date</td>
    <td>Sale Price</td>
    <td>Sale From Date</td>
    <td>Sale End Date</td>
    <td>Item Condition</td>
    <td>Offer Condition Note</td>
    <td>Handling Time</td>
    <td>Restock Date</td>
    <td>Maximum Aggregate Ship Quantity</td>
    <td>Can Be Gift Messaged</td>
    <td>Is Gift Wrap Available?</td>
    <td>Is Discontinued by Manufacturer</td>
    <td>Registered Parameter</td>
    <td>Business Price</td>
    <td>Quantity Price Type</td>
    <td>Quantity Lower Bound 1</td>
    <td>Quantity Price 1</td>
    <td>Quantity Lower Bound 2</td>
    <td>Quantity Price 2</td>
    <td>Quantity Lower Bound 3</td>
    <td>Quantity Price 3</td>
    <td>Quantity Lower Bound 4</td>
    <td>Quantity Price 4</td>
    <td>Quantity Lower Bound 5</td>
    <td>Quantity Price 5</td>
    <td>National Stock Number</td>
    <td>United Nations Standard Products and Services Code</td>
    <td>Pricing Action</td>
  </tr>
  <tr height="45">
    <td height="45">feed_product_type</td>
    <td>item_sku</td>
    <td>brand_name</td>
    <td>item_name</td>
    <td>manufacturer</td>
    <td>recommended_browse_nodes</td>
    <td>standard_price</td>
    <td>quantity</td>
    <td>merchant_shipping_group_name</td>
    <td>main_image_url</td>
    <td>swatch_image_url</td>
    <td>other_image_url1</td>
    <td>other_image_url2</td>
    <td>other_image_url3</td>
    <td>other_image_url4</td>
    <td>other_image_url5</td>
    <td>other_image_url6</td>
    <td>other_image_url7</td>
    <td>other_image_url8</td>
    <td>parent_child</td>
    <td>parent_sku</td>
    <td>relationship_type</td>
    <td>variation_theme</td>
    <td>update_delete</td>
    <td>gtin_exemption_reason</td>
    <td>external_product_id</td>
    <td>external_product_id_type</td>
    <td>part_number</td>
    <td>product_description</td>
    <td>catalog_number</td>
    <td>bullet_point1</td>
    <td>bullet_point2</td>
    <td>bullet_point3</td>
    <td>bullet_point4</td>
    <td>bullet_point5</td>
    <td>generic_keywords1</td>
    <td>generic_keywords2</td>
    <td>generic_keywords3</td>
    <td>generic_keywords4</td>
    <td>generic_keywords5</td>
    <td>platinum_keywords1</td>
    <td>platinum_keywords2</td>
    <td>platinum_keywords3</td>
    <td>platinum_keywords4</td>
    <td>platinum_keywords5</td>
    <td>target_audience_keywords</td>
    <td>size_map</td>
    <td>length_range</td>
    <td>width_range</td>
    <td>scent_name</td>
    <td>color_name</td>
    <td>color_map</td>
    <td>size_name</td>
    <td>material_type</td>
    <td>item_width_unit_of_measure</td>
    <td>item_width</td>
    <td>item_height</td>
    <td>item_height_unit_of_measure</td>
    <td>item_dimensions_unit_of_measure</td>
    <td>item_length_unit_of_measure</td>
    <td>item_length</td>
    <td>item_display_depth</td>
    <td>item_display_depth_unit_of_measure</td>
    <td>website_shipping_weight</td>
    <td>website_shipping_weight_unit_of_measure</td>
    <td>item_display_length</td>
    <td>item_display_length_unit_of_measure</td>
    <td>item_display_width</td>
    <td>item_display_width_unit_of_measure</td>
    <td>item_display_height</td>
    <td>item_display_height_unit_of_measure</td>
    <td>item_display_diameter</td>
    <td>item_display_diameter_unit_of_measure</td>
    <td>item_display_weight</td>
    <td>item_display_weight_unit_of_measure</td>
    <td>volume_capacity_name</td>
    <td>volume_capacity_name_unit_of_measure</td>
    <td>item_display_volume</td>
    <td>item_display_volume_unit_of_measure</td>
    <td>package_weight_unit_of_measure</td>
    <td>package_dimensions_unit_of_measure</td>
    <td>package_weight</td>
    <td>package_length</td>
    <td>package_width</td>
    <td>package_height</td>
    <td>fulfillment_center_id</td>
    <td>specific_uses_for_product1</td>
    <td>specific_uses_for_product2</td>
    <td>specific_uses_for_product3</td>
    <td>specific_uses_for_product4</td>
    <td>specific_uses_for_product5</td>
    <td>product_efficiency_image_url</td>
    <td>energy_efficiency_image_url</td>
    <td>legal_disclaimer_description</td>
    <td>safety_warning</td>
    <td>fedas_id</td>
    <td>eu_toys_safety_directive_age_warning</td>
    <td>eu_toys_safety_directive_warning</td>
    <td>eu_toys_safety_directive_language</td>
    <td>country_string</td>
    <td>are_batteries_included</td>
    <td>batteries_required</td>
    <td>battery_type1</td>
    <td>battery_type2</td>
    <td>battery_type3</td>
    <td>number_of_batteries1</td>
    <td>number_of_batteries2</td>
    <td>number_of_batteries3</td>
    <td>battery_cell_composition</td>
    <td>battery_weight</td>
    <td>battery_weight_unit_of_measure</td>
    <td>number_of_lithium_metal_cells</td>
    <td>number_of_lithium_ion_cells</td>
    <td>lithium_battery_packaging</td>
    <td>lithium_battery_energy_content</td>
    <td>lithium_battery_energy_content_unit_of_measure</td>
    <td>lithium_battery_weight</td>
    <td>lithium_battery_weight_unit_of_measure</td>
    <td>supplier_declared_dg_hz_regulation1</td>
    <td>supplier_declared_dg_hz_regulation2</td>
    <td>supplier_declared_dg_hz_regulation3</td>
    <td>supplier_declared_dg_hz_regulation4</td>
    <td>supplier_declared_dg_hz_regulation5</td>
    <td>hazmat_united_nations_regulatory_id</td>
    <td>safety_data_sheet_url</td>
    <td>item_weight</td>
    <td>item_weight_unit_of_measure</td>
    <td>item_volume</td>
    <td>item_volume_unit_of_measure</td>
    <td>flash_point</td>
    <td>ghs_classification_class1</td>
    <td>ghs_classification_class2</td>
    <td>ghs_classification_class3</td>
    <td>list_price</td>
    <td>weee_tax_value</td>
    <td>number_of_items</td>
    <td>weee_tax_value_unit_of_measure</td>
    <td>offering_end_date</td>
    <td>max_order_quantity</td>
    <td>offering_start_date</td>
    <td>delivery_schedule_group_id</td>
    <td>product_site_launch_date</td>
    <td>currency</td>
    <td>item_package_quantity</td>
    <td>product_tax_code</td>
    <td>merchant_release_date</td>
    <td>sale_price</td>
    <td>sale_from_date</td>
    <td>sale_end_date</td>
    <td>condition_type</td>
    <td>condition_note</td>
    <td>fulfillment_latency</td>
    <td>restock_date</td>
    <td>max_aggregate_ship_quantity</td>
    <td>offering_can_be_gift_messaged</td>
    <td>offering_can_be_giftwrapped</td>
    <td>is_discontinued_by_manufacturer</td>
    <td>missing_keyset_reason</td>
    <td>business_price</td>
    <td>quantity_price_type</td>
    <td>quantity_lower_bound1</td>
    <td>quantity_price1</td>
    <td>quantity_lower_bound2</td>
    <td>quantity_price2</td>
    <td>quantity_lower_bound3</td>
    <td>quantity_price3</td>
    <td>quantity_lower_bound4</td>
    <td>quantity_price4</td>
    <td>quantity_lower_bound5</td>
    <td>quantity_price5</td>
    <td>national_stock_number</td>
    <td>unspsc_code</td>
    <td>pricing_action</td>
  </tr>';
  while($row=mysql_fetch_array($result)){
    $key1="";
	$key2="";
	$key3="";
	$key4="";
	$key5="";
	$img1="";
	$img2="";
	$img3="";
	$img4="";
	$img5="";
	$img6="";
	$img7="";
	$img8="";
	$img9="";
	if(!empty($row[keywords])){
	$key=explode("\r\n",$row[keywords]);
	if(!empty($key[0])){$key1=$key[0];}
	if(!empty($key[1])){$key2=$key[1];}
	if(!empty($key[2])){$key3=$key[2];}
	if(!empty($key[3])){$key4=$key[3];}
	if(!empty($key[4])){$key5=$key[4];}
	}
	
	$sqla="select * from ph_img where proid='".$row[ID]."' and btid is null order by px asc";
	$resulta=mysql_query($sqla);
	while($rowa=mysql_fetch_array($resulta)){
	if(!empty($rowa[imgpath])){$img1="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img1="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img2="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img2="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img3="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img3="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img4="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img4="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img5="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img5="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img6="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img6="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img7="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img7="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img8="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img8="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img9="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img9="";}
	}
	$rowa=null;
	unset($rowa);
    $spliter="&lt;br/&gt;";
	$content=str_replace("\r\n",$spliter,$row[content]);
    $content=htmlentities($content);
	$sqls="select * from ph_shuxing where proid='".$row[ID]."' order by ID asc";
  $results=mysql_query($sqls);
  $sku=$row[skucode];
  $content=replacebd($content,$brand);
  if(strpos($row[des], $spliter)==false){
    $des=explode($spliter,$content);
  }else{
    $des=explode("\r\n",$row[des]);
  }
	$des1=$des[0];
	$des2=$des[1];
	$des3=$des[2];
	$des4=$des[3];
	$des5=$des[4];
  //if(mysql_num_rows($results)<1){$upc="UPC";$sku=$row[skucode];$parent="";}else{$upc="";$sku="";$parent="parent";}
  $tablebody.='<tr height="45">
    <td height="45">'.$ProductType.'</td>
    <td>'.$sku.'</td>
    <td>'.$brand.'</td>
    <td>'.$row[proname].'</td>
    <td>'.$manufacturer.'</td>
    <td>'.$recommended.'</td>
    <td></td>
    <td></td>
    <td>Migrated Template</td>
    <td>'.$img1.'</td>
    <td>'.$img1.'</td>
    <td>'.$img2.'</td>
    <td>'.$img3.'</td>
    <td>'.$img4.'</td>
    <td>'.$img5.'</td>
    <td>'.$img6.'</td>
	<td>'.$img7.'</td>
	<td>'.$img8.'</td>
	<td>'.$img9.'</td>
    <td>parent</td>
    <td></td>
    <td></td>
    <td>'.$row[btname].'</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>'.$content.'</td>
	<td></td>
    <td>'.$des1.'</td>
    <td>'.$des2.'</td>
    <td>'.$des3.'</td>
    <td>'.$des4.'</td>
    <td>'.$des5.'</td>
    <td>'.$key1.'</td>
    <td>'.$key2.'</td>
    <td>'.$key3.'</td>
    <td>'.$key4.'</td>
    <td>'.$key5.'</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>New</td>
    <td></td>
    <td>10</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>';  
  if(mysql_num_rows($results)<1){
    $tablebody.='<tr height="45">
    <td height="45">'.$ProductType.'</td>
    <td>'.$sku.'-1'.'</td>
    <td>'.$brand.'</td>
    <td>'.$row[proname].'</td>
    <td>'.$manufacturer.'</td>
    <td>'.$recommended.'</td>
    <td>'.$row[saleprice].'</td>
    <td>'.$row[kucun].'</td>
    <td>Migrated Template</td>
    <td>'.$img1.'</td>
    <td>'.$img1.'</td>
    <td>'.$img2.'</td>
    <td>'.$img3.'</td>
    <td>'.$img4.'</td>
    <td>'.$img5.'</td>
    <td>'.$img6.'</td>
    <td>'.$img7.'</td>
    <td>'.$img8.'</td>
    <td>'.$img9.'</td>
    <td>child</td>
    <td>'.$sku.'</td>
    <td>Variation</td>
    <td>'.$row[btname].'</td>
    <td>update</td>
    <td></td>
    <td style="mso-number-format:\'\@\';">'.EAN13(randomkeys(12)).'</td>
    <td>EAN</td>
    <td></td>
    <td>'.$content.'</td>
    <td></td>
    <td>'.$des1.'</td>
    <td>'.$des2.'</td>
    <td>'.$des3.'</td>
    <td>'.$des4.'</td>
    <td>'.$des5.'</td>
    <td>'.$key1.'</td>
    <td>'.$key2.'</td>
    <td>'.$key3.'</td>
    <td>'.$key4.'</td>
    <td>'.$key5.'</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>One size</td>
    <td></td>
    <td></td>
    <td></td>
    <td>color</td>
    <td>color</td>
    <td>One size</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>New</td>
    <td></td>
    <td>10</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>';
  }else{
  $i=0;
  while($rows=mysql_fetch_array($results)){
  $btimg1="";
  $btimg2="";
  $btimg3="";
  $btimg4="";
  $btimg5="";
  $btimg6="";
  $btimg7="";
  $btimg8="";
  $btimg9="";
  $i=$i+1;
  if(strpos($rows[cname],",")!==false){$cname=explode(",",$rows[cname]);$cname1=$cname[0];$cname2=$cname[1];}else{$cname1=$rows[cname];$cname2="";}
  $sqlb="select * from ph_img where btid='".$rows[ID]."'";
	$resultb=mysql_query($sqlb);
	while($rowb=mysql_fetch_array($resultb)){

	if(!empty($rowb[imgpath])){$btimg1="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg1=$img1;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg2="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg2=$img2;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg3="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg3=$img3;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg4="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg4=$img4;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg5="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg5=$img5;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg6="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg6=$img6;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg7="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg7=$img7;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg8="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg8=$img8;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg9="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg9=$img9;}
	}
  $tablebody.='<tr height="45">
    <td height="45">'.$ProductType.'</td>
    <td>'.$sku.'-'.$i.'</td>
    <td>'.$brand.'</td>
    <td>'.$row[proname].",".$rows[cname].'</td>
    <td>'.$manufacturer.'</td>
    <td>'.$recommended.'</td>
    <td>'.$rows[saleprice].'</td>
    <td>'.$rows[kucun].'</td>
    <td>Migrated Template</td>
    <td>'.$btimg1.'</td>
    <td>'.$btimg1.'</td>
    <td>'.$btimg2.'</td>
    <td>'.$btimg3.'</td>
    <td>'.$btimg4.'</td>
    <td>'.$btimg5.'</td>
    <td>'.$btimg6.'</td>
	<td>'.$btimg7.'</td>
	<td>'.$btimg8.'</td>
	<td>'.$btimg9.'</td>
    <td>child</td>
    <td>'.$sku.'</td>
    <td>Variation</td>
    <td>'.$row[btname].'</td>
    <td>update</td>
    <td></td>
    <td style="mso-number-format:\'\@\';">'.EAN13(randomkeys(12)).'</td>
    <td>EAN</td>
    <td></td>
    <td>'.$content.'</td>
	<td></td>
    <td>'.$des1.'</td>
    <td>'.$des2.'</td>
    <td>'.$des3.'</td>
    <td>'.$des4.'</td>
    <td>'.$des5.'</td>
    <td>'.$key1.'</td>
    <td>'.$key2.'</td>
    <td>'.$key3.'</td>
    <td>'.$key4.'</td>
    <td>'.$key5.'</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>'.$cname2.'</td>
    <td></td>
    <td></td>
    <td></td>
    <td>'.$cname1.'</td>
    <td>'.$cname1.'</td>
    <td>'.$cname2.'</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>New</td>
    <td></td>
    <td>10</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>';
  }
  }
  }
  $tablefoot='</table>
</body>
</html>';
//echo $tablehead.$tablebody.$tablefoot;
export_xls($bname."-".date('Ymdhis', time()).".xls",$tablehead.$tablebody.$tablefoot);
}
?>
